<?php
/**
 * Created by PhpStorm.
 * Author: shishiwenjie
 * Date: 2018/5/19
 * Time: 16:48
 */

namespace app\company\controller;
use think\Controller;
use think\Db;
use think\Session;

class Content extends Controller
{
    //进入发布招聘列表界面，未登录则跳转回登录界面
   function  index(){


           $Mcontent = new \app\company\model\Content();
           $res = $Mcontent->where('jigou_id', Session::get('id'))->select();
           $this->assign("res", $res);
           return view("content");

   }
    function  fbzp(){
        if( !session('?jigou')) {
            return $this->redirect('Users/login');
        }else {
            return view("fbzp");
        }
    }
    function addzhaop()
    {
        $id=Session::get('id');
        $res = Db::name('liewu_jigou')->where("id", $id)->find();
        $units =$res['name'];

        //获取请求的数据
        $data = [
            'jigou_id' => $id,
            'units' => $units,
            'jobname' => $_POST['jobname'],
            'jobsalary' => $_POST['money'],
            'renshu' => $_POST['renshu'],
            'jobtype' => $_POST['jobtype'],
            'aboutjob' => $_POST['aboutjob'],
            'date'=>$_POST['date'],
//            'awards'=>$_POST['awards']
        ];
        $rule=[
            'jobname|岗位名称'=>'require',
            'jobsalary|岗位薪资'=>'require',
            'renshu|招聘人数'=>'require',
            'jobtype|类型'=>'require',
            'aboutjob|岗位描述'=>'require',
        ];
        $check = $this->validate($data, $rule);
        //true 使用模型层的对象进行数据的添加
        if (true !== $check) {
            //返回错误信息
            return ['status' => -1, 'message' => $check];
        } else {
            $res = Db::name('liewu_hiring')->insert($data);
            if ($res) {
                return ['status' => 1, 'message' => "恭喜,发布招聘成功"];
            } else {
                return ['status' => 0, 'message' => "发布失败,请检查"];
            }
        }
    }
    function del(){
        if( !session('?jigou')) {
            return $this->redirect('Users/login');
        }else {
            //获取请求的数据
            $data = [
                'id' => $_POST['id']
            ];
            //true 使用模型层的对象进行数据的添加
            $res = Db::name('liewu_hiring')->where("id", $data['id'])->delete();
            if ($res) {
                return ['status' => 1, 'message' => "删除成功"];
            } else {
                return ['status' => 0, 'message' => "删除失败,请检查"];
            }
        }
    }
    function update()
    {
        if (!session('?jigou')) {
            return $this->redirect('Users/login');
        } else {
            //获取请求的数据
            $data = [
                'id' => $_GET['id']
            ];
            $res = Db::name('liewu_hiring')->where("id", $data['id'])->find();

            $this->assign("res", $res);
            return view("updatezp");
        }
    }
    function update2()
    {
        //获取请求的数据
        $data = [
            'id'=>$_POST['id'],
            'jigou_id' => Session::get('id'),
            'units' => Session::get('jigouname'),
            'jobname' => $_POST['jobname'],
            'jobsalary' => $_POST['money'],
            'renshu' => $_POST['renshu'],
            'jobtype' => $_POST['jobtype'],
            'aboutjob' => $_POST['aboutjob'],
            'date'=>$_POST['date']
//            'awards'=>$_POST['awards']
        ];
        //true 使用模型层的对象进行数据的修改
        $res = Db::name('liewu_hiring')->where("id",$data['id'])->update($data);
        if ($res) {
            return ['status' => 1, 'message' => "恭喜,修改成功"];
        } else {
            return ['status' => 0, 'message' => "修改失败,请检查"];
        }
    }
}